﻿function runScriptOfNewsDetailPage() {
    var lastParagraph = $("#newscontent p:last");
    if ($.trim(lastParagraph.html()) == "" || $.trim(lastParagraph.html()) == "&nbsp;") {
        lastParagraph.remove();
    }

    //begin: linkhay button
    if (typeof LHClass_Link_Post_Embed == 'undefined') {
        if (typeof LH_Link_Post_Embed_Loader == 'undefined') {
            var LH_Link_Post_Embed_Loader = document.createElement('script');

            LH_Link_Post_Embed_Loader.type = 'text/javascript';
            LH_Link_Post_Embed_Loader.src = 'http://linkhay2.vcmedia.vn/live/js/link/post/adapter/embed/main.js';

            document.getElementsByTagName('head')[0].appendChild(LH_Link_Post_Embed_Loader);
        }
    } else {
        LH_Link_Post_Embed_Scan();
    }
    //end: linkhay button

    //G+
    window.___gcfg = { lang: 'vi' };

    (function () {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();



    $(".VCSortableInPreviewMode").each(function () {
        if ($(this).attr("type") == "Photo") {
            $(this).wrap("<p class=\"VCSortableInPreviewModeWrapper\"></p>");
            var img = $(this).find("img:first");

            if (img.width() <= 0) {
                var recentWidth = 0;
                var parent = $(this);
                img.bind('load', function () {
                    if ($(this).width() > recentWidth) {
                        recentWidth = $(this).width();
                        parent.width(recentWidth);
                    }
                });
            } else {
                $(this).width(img.width());
            }
        }
        else if ($(this).attr("type") == "RelatedNews") {
            $(this).find("a").css({ "color": "#414141", "font-weight": "bold" });
            var images = $(this).find("img");
            if (images.length > 0) {
                images.each(function () {
                    if ($(this).attr("src").indexOf("/http://sohanews2.vcmedia.vn") != -1) {
                        $(this).attr("src", $(this).attr("src").replace("/http://sohanews2.vcmedia.vn", ""));
                    }
                });
            }
        } else if ($(this).attr("type") == "content") {
            if ($(this).css('float') == 'left') {
                $(this).css({ 'margin': '0 10px 0 0' });
            } else if ($(this).css('float') == 'right') {
                $(this).css({ 'margin': '0 0 0 10px' });
            }
        } else if ($(this).attr("type") == "Video") {
            $(this).wrap("<p class=\"VCSortableInPreviewModeWrapper\"></p>");
        }
    });

    var color = "#e52c4b";
    var currentcolor = "#545454";
    $(".VCSortableInPreviewMode").each(function () {

        if ($(this).attr("type") == "RelatedNews") {
            $(this).css("border-top", "solid 3px #e52c4b");
            if ($(this).width() >= 600) {
                $(this).wrap("<center />").css({ 'min-width': '600px', 'display': 'block' });
                $(this).addClass("fix");
            }
        }

    });
    $(".VCSortableInPreviewMode a").hover(
    function () {
        $(this).css("color", color);
    },
    function () {
        $(this).css("color", currentcolor);
    }
    );

    $("#newscontent img").each(function () {
        if ($(this).width() > 638 && $(this).attr("src").indexOf("http://sohanews2.vcmedia.vn/") != -1) {
            $(this).attr("src", $(this).attr("src").replace("http://sohanews2.vcmedia.vn/", "http://sohanews2.vcmedia.vn/thumb_w/600/"));
        }
    });
}



